using System;
using K9Nano.MultiTenancy;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using TestBase;
using Xunit.Abstractions;

namespace RuntimeTest
{
    public abstract class RuntimeTestBase
    {
        protected readonly IServiceProvider ServiceProvider;
        protected readonly ILogger Logger;

        protected RuntimeTestBase(ITestOutputHelper testOutputHelper)
        {
            var services = new ServiceCollection()
                .AddK9NanoCore(null)
                .AddLogging(builder => { builder.AddProvider(new XunitLoggerProvider(testOutputHelper)); })
                .AddTransient<ITenantStore, NullTenantStore>();
            AddServices(services);
            ServiceProvider = services.BuildServiceProvider(); ;
            Logger = ServiceProvider.GetService<ILoggerFactory>().CreateLogger(this.GetType().Name);
        }

        protected virtual void AddServices(IServiceCollection services)
        {
        }
    }
}
